package com.ayz.gateway.client.executor;


import com.ayz.gateway.client.exception.CurrentMethodNotSupportException;
import com.ayz.gateway.client.exception.ExecuteRequestException;
import io.grpc.ManagedChannel;
import lombok.Data;

import java.util.concurrent.TimeoutException;

/**
 * @ClassName GrpcRequestExecutor
 * @Description TODO: Grpc请求执行器
 * @Author 快乐的星球
 * @Date 2023/5/20 16:03
 * @Version 1.0
 **/
@Data
public abstract class GrpcRequestExecutor<Req,Resp> implements RequestExecutor<Req,Resp>{


    /**
     * 通过GRPC传输通道向服务器发起请求
     * 同步请求
     * @param managedChannel 传输通道
     * @param request 请求
     * @param timeoutMills 超时时间
     * @return
     * @throws TimeoutException
     * @throws ExecuteRequestException
     */
    public Resp request(ManagedChannel managedChannel,Req request,long timeoutMills)throws TimeoutException, ExecuteRequestException {
        return null;
    }

    /**
     * 异步请求
     * @param managedChannel
     * @param request
     * @param responseCallback
     * @throws TimeoutException
     * @throws ExecuteRequestException
     */
    public void asyncRequest(ManagedChannel managedChannel,Req request,ResponseCallback<Resp> responseCallback)throws TimeoutException, ExecuteRequestException{
    }

    /**
     * 向服务器单向的发起请求不需要等待结果
     * @param managedChannel
     * @param request
     * @throws ExecuteRequestException
     */
    public void requestOneway(ManagedChannel managedChannel,Req request) throws ExecuteRequestException{
    }
    @Override
    public Resp request(Req request, long timeoutMills) throws TimeoutException, ExecuteRequestException {
        throw new CurrentMethodNotSupportException("GrpcRequestExecutor类中不支持 request方法");
    }

    @Override
    public void asyncRequest(Req request, ResponseCallback<Resp> responseCallback) throws TimeoutException, ExecuteRequestException {
        throw new CurrentMethodNotSupportException("GrpcRequestExecutor类中不支持 asyncRequest方法");
    }

    @Override
    public void requestOneway(Req request) throws ExecuteRequestException {
        throw new CurrentMethodNotSupportException("GrpcRequestExecutor类中不支持 requestOneway方法");
    }
}
